Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-91133: tempfile.TemporaryDirectory: fix symlink bug in cleanup #99930

Merged
merged 15 commits into from
Dec 7, 2023

Conversation

kwi-dk
Copy link
Contributor

@kwi-dk kwi-dk commented Dec 1, 2022

This PR fixes issue gh-91133, in which TemporaryDirectory.cleanup could try to fix permissions when deleting a symlink, but accidentally fix permissions of the target of the symlink instead.

(It also changes the test_flags test case so it doesn't leave behind NOUNLINK files when the test fails, which is just annoying when working on any change to the TemporaryDirectory code.)

Compatibility: There could conceivably be code out there relying on TemporaryDirectory.cleanup modifying permissions on files outside the tempdir being cleaned up, which the fixed code will no longer do.

@cpython-cla-bot
Copy link

cpython-cla-bot bot commented Dec 1, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

During development, it becomes tiresome to have to manually clean up
these files in case of unrelated TemporaryDirectory breakage.
@netlify
Copy link

netlify bot commented Dec 14, 2022

Deploy Preview for python-cpython-preview ready!

Name Link
🔨 Latest commit db40615
🔍 Latest deploy log https://app.netlify.com/sites/python-cpython-preview/deploys/639b60bbd252c20008d29de1
😎 Deploy Preview https://deploy-preview-99930--python-cpython-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Member

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to me like a good fix, thanks! A few comments.

Lib/test/test_tempfile.py Outdated Show resolved Hide resolved
Lib/test/test_tempfile.py Outdated Show resolved Hide resolved
Copy link
Member

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo one more comment. Thanks!

Lib/test/test_tempfile.py Outdated Show resolved Hide resolved
@arhadthedev arhadthedev added the stdlib Python modules in the Lib dir label Feb 28, 2023
@arhadthedev
Copy link
Member

@serhiy-storchaka and @vstinner (as active committers into tempfile.py)

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I prefer to test with real filesystem. Mock tests are too fragile, they depend on implementation details that can be changed.

Lib/tempfile.py Outdated
@@ -874,15 +874,22 @@ def __init__(self, suffix=None, prefix=None, dir=None,

@classmethod
def _rmtree(cls, name, ignore_errors=False):
def without_following_symlinks(func, path, *args):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to rename the function to "no_follow_symlinks" or "dont_follow_symlinks".

I dislike this trend to declare nested functions. Can't you move these functions at the module level, just make them private? This function doesn't use name nor ignore_errors.

@bedevere-app
Copy link

bedevere-app bot commented Dec 7, 2023

GH-112838 is a backport of this pull request to the 3.12 branch.

@miss-islington-app
Copy link

Sorry, @kwi-dk and @serhiy-storchaka, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 81c16cd94ec38d61aa478b9a452436dc3b1b524d 3.11

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 7, 2023
…up (pythonGH-99930)

(cherry picked from commit 81c16cd)

Co-authored-by: Søren Løvborg <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Dec 7, 2023
@miss-islington-app
Copy link

Sorry, @kwi-dk and @serhiy-storchaka, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 81c16cd94ec38d61aa478b9a452436dc3b1b524d 3.10

@miss-islington-app
Copy link

Sorry, @kwi-dk and @serhiy-storchaka, I could not cleanly backport this to 3.9 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 81c16cd94ec38d61aa478b9a452436dc3b1b524d 3.9

@miss-islington-app
Copy link

Sorry, @kwi-dk and @serhiy-storchaka, I could not cleanly backport this to 3.8 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 81c16cd94ec38d61aa478b9a452436dc3b1b524d 3.8

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Dec 7, 2023
…n cleanup (pythonGH-99930)

(cherry picked from commit 81c16cd)

Co-authored-by: Søren Løvborg <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Dec 7, 2023

GH-112839 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Dec 7, 2023
@afeblot
Copy link

afeblot commented Dec 7, 2023

I opened the issue this is fixing. Thank you all for the fix.

@bedevere-app
Copy link

bedevere-app bot commented Dec 7, 2023

GH-112840 is a backport of this pull request to the 3.10 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.10 only security fixes label Dec 7, 2023
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Dec 7, 2023
…n cleanup (pythonGH-99930)

(cherry picked from commit 81c16cd)

Co-authored-by: Søren Løvborg <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Dec 7, 2023

GH-112842 is a backport of this pull request to the 3.9 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.9 only security fixes label Dec 7, 2023
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Dec 7, 2023
… cleanup (pythonGH-99930)

(cherry picked from commit 81c16cd)

Co-authored-by: Søren Løvborg <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Dec 7, 2023

GH-112843 is a backport of this pull request to the 3.8 branch.

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Dec 7, 2023
… cleanup (pythonGH-99930)

(cherry picked from commit 81c16cd)

Co-authored-by: Søren Løvborg <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this pull request Dec 7, 2023
…nup (GH-99930) (GH-112838)

(cherry picked from commit 81c16cd)

Co-authored-by: Søren Løvborg <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this pull request Dec 7, 2023
…nup (GH-99930) (GH-112839)

(cherry picked from commit 81c16cd)

Co-authored-by: Søren Løvborg <[email protected]>
@vstinner
Copy link
Member

vstinner commented Dec 7, 2023

Thanks @kwi-dk for this fix. Thanks @serhiy-storchaka to taking the lead to update the code and merge the fix!

ambv pushed a commit that referenced this pull request Jan 17, 2024
…up (GH-99930) (GH-112843)

(cherry picked from commit 81c16cd)

Co-authored-by: Søren Løvborg <[email protected]>
ambv pushed a commit that referenced this pull request Jan 17, 2024
…up (GH-99930) (GH-112842)

(cherry picked from commit 81c16cd)

Co-authored-by: Søren Løvborg <[email protected]>
ambv pushed a commit that referenced this pull request Jan 17, 2024
…nup (GH-99930) (GH-112840)

(cherry picked from commit 81c16cd)

Co-authored-by: Søren Løvborg <[email protected]>
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-security A security issue
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants